﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using WL_Store.BLL;
using WL_Store.Model;

namespace WL_Store.Web.subpage
{
    public partial class user_list_edit : System.Web.UI.Page
    {
        VipInfoBLL bll = new VipInfoBLL();
        protected void Page_Load(object sender, EventArgs e)
        {
            
            if (!IsPostBack)
            {
                int vipId = Convert.ToInt32(Request.QueryString["vipId"]);

                VipInfoModel model = bll.VipInfo(vipId);
                if (model!=null)
                {
                    this.txt_id.Text = vipId.ToString();
                    this.txt_vipcard.Text = model.vipcard.ToString();
                    this.txt_name.Text = model.vipname.ToString();
                    this.rbl_sex.SelectedValue =model.sex?"1":"0";
                    this.txt_phone.Text = model.phone;
                    this.txt_adress.Text = model.address;
                    this.txt_grade.Text = model.grade;

                }
            }
        }

        protected void btn_add_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                int vipId = Convert.ToInt32(Request.QueryString["vipId"]);

                VipInfoModel model = new VipInfoModel();

                model.vipId = vipId;
                model.vipcard = Convert.ToInt32(this.txt_vipcard.Text.Trim());
                model.vipname = this.txt_name.Text.Trim();
                model.sex = Convert.ToBoolean(Convert.ToInt32( this.rbl_sex.SelectedValue));
                model.phone = this.txt_phone.Text.Trim();
                model.address = this.txt_adress.Text.Trim();
                model.grade = this.txt_grade.Text.Trim();

                if (bll.UpdatevipInfoProc(model))
                {
                    Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "<script>alert('修改成功！');location.href='user_list.aspx'</script>");
                }
                else
                {
                    Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "<script>alert('修改失败！')</script>");
                }


            }
        }
    }
}